home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / src / unix / c / close < prev    next >
Text File  |  1991-09-20  |  626b  |  45 lines

  1. static char sccs_id[] = "@(#) close.c 1.3 "__DATE__" HJR";
  2.  
  3. /* close.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <errno.h>
  6.  
  7. #include "fcntl.h"
  8.  
  9. #include "sys/types.h"
  10. #include "sys/unix.h"
  11. #include "sys/dev.h"
  12. #include "sys/os.h"
  13.  
  14. int close(int fd)
  15. {
  16. register struct file *f;
  17.  
  18. if (BADF(fd))
  19.   {
  20.   errno = EBADF;
  21.   return(-1);
  22.   }
  23.  
  24. f = __u->file + fd;
  25.  
  26. if (f->dup != f)
  27.   {
  28.   register struct file *_f;
  29.  
  30.   _f = f->dup; while (_f->dup != f) { _f = _f->dup; }
  31.  
  32.   _f->dup = f->dup;
  33.   }
  34. else
  35.   {
  36.   if (f->pid == __u->pid)
  37.     if ((*(__dev[major(f->dev)].close))(minor(f->dev),f) < 0)
  38.       return(-1);
  39.   }
  40.  
  41. f->dup = 0;
  42.  
  43. return(0);
  44. }
  45.